## Create Figure A6

## Loading packages
library(readxl)
library(tidyverse)
library(lubridate)
library(sf)
library(foreign)
library(haven)

## Load data
dta = read_stata("dta.dta")


schools_per_year = dta %>%
  mutate(n = 1) %>%
  group_by(school_year, district) %>%
  summarise(n_school = sum(n))

schools_received = dta %>%
  left_join(., schools_per_year, by = c("district", "school_year")) %>%
  group_by(school_year, district, n_school) %>%
  summarise(ldp_received = sum(ldp_received, na.rm = TRUE)) %>%
  mutate(share_schools_ldp = ldp_received/n_school*100)

## Panel A
share_schools_ldp1 = ggplot(schools_received %>% filter(district == 1), 
                            aes(x = factor(school_year), y = share_schools_ldp)) +
  geom_bar(stat = "identity",color="black", fill="gray") +
  geom_text(aes(label=
                  paste0(I(round(share_schools_ldp, digits = 2)), "%")), 
            position=position_dodge(width=0.9), vjust=-0.45, size = 2.5) +
  scale_x_discrete(labels= c("2011-2012", "2012-2013", "2013-2014", "2014-2015",
                             "2015-2016", "2016-2017", "2017-2018", "2018-2019",
                             "2019-2020")) +
  labs(x = "School Year", y = "Share of Schools Receiving \n 1+ ldp Projects") +
  scale_y_continuous(limits = c(0, 25), labels = function(x) paste0(x, "%"))+
  theme_bw() +
  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "black"),
        axis.text.x = element_text(angle = 45, hjust=1))

## Panel B
share_schools_ldp2 = ggplot(schools_received %>% filter(district == 2), 
                            aes(x = factor(school_year), y = share_schools_ldp)) +
  geom_bar(stat = "identity",color="black", fill="gray") +
  geom_text(aes(label=
                  paste0(I(round(share_schools_ldp, digits = 2)), "%")), 
            position=position_dodge(width=0.9), vjust=-0.45, size = 2.5) +
  scale_x_discrete(labels= c("2011-2012", "2012-2013", "2013-2014", "2014-2015",
                             "2015-2016", "2016-2017", "2017-2018", "2018-2019",
                             "2019-2020")) +
  labs(x = "School Year", y = "Share of Schools Receiving \n 1+ ldp Projects") +
  scale_y_continuous(limits = c(0, 20), labels = function(x) paste0(x, "%"))+
  theme_bw() +
  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "black"),
        axis.text.x = element_text(angle = 45, hjust=1))

## Panel C
share_schools_ldp3 = ggplot(schools_received %>% filter(district == 3), 
                            aes(x = factor(school_year), y = share_schools_ldp)) +
  geom_bar(stat = "identity",color="black", fill="gray") +
  geom_text(aes(label=
                  paste0(I(round(share_schools_ldp, digits = 2)), "%")), 
            position=position_dodge(width=0.9), vjust=-0.45, size = 2.5) +
  scale_x_discrete(labels= c("2011-2012", "2012-2013", "2013-2014", "2014-2015",
                             "2015-2016", "2016-2017", "2017-2018", "2018-2019",
                             "2019-2020")) +
  labs(x = "School Year", y = "Share of Schools Receiving \n 1+ ldp Projects") +
  scale_y_continuous(limits = c(0,20), labels = function(x) paste0(x, "%"))+
  theme_bw() +
  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "black"),
        axis.text.x = element_text(angle = 45, hjust=1))

## Panel D
share_schools_ldp4 = ggplot(schools_received %>% filter(district == 4), 
                            aes(x = factor(school_year), y = share_schools_ldp)) +
  geom_bar(stat = "identity",color="black", fill="gray") +
  geom_text(aes(label=
                  paste0(I(round(share_schools_ldp, digits = 2)), "%")), 
            position=position_dodge(width=0.9), vjust=-0.45, size = 2.5) +
  scale_x_discrete(labels= c("2011-2012", "2012-2013", "2013-2014", "2014-2015",
                             "2015-2016", "2016-2017", "2017-2018", "2018-2019",
                             "2019-2020")) +
  labs(x = "School Year", y = "Share of Schools Receiving \n 1+ ldp Projects") +
  scale_y_continuous(limits = c(0,35), labels = function(x) paste0(x, "%"))+
  theme_bw() +
  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "black"),
        axis.text.x = element_text(angle = 45, hjust=1))

## Panel E
share_schools_ldp5 = ggplot(schools_received %>% filter(district == 5), 
                            aes(x = factor(school_year), y = share_schools_ldp)) +
  geom_bar(stat = "identity",color="black", fill="gray") +
  geom_text(aes(label=
                  paste0(I(round(share_schools_ldp, digits = 2)), "%")), 
            position=position_dodge(width=0.9), vjust=-0.45, size = 2.5) +
  scale_x_discrete(labels= c("2011-2012", "2012-2013", "2013-2014", "2014-2015",
                             "2015-2016", "2016-2017", "2017-2018", "2018-2019",
                             "2019-2020")) +
  labs(x = "School Year", y = "Share of Schools Receiving \n 1+ ldp Projects") +
  scale_y_continuous(limits = c(0,25), labels = function(x) paste0(x, "%"))+
  theme_bw() +
  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "black"),
        axis.text.x = element_text(angle = 45, hjust=1))

## Panel F
share_schools_ldp6 = ggplot(schools_received %>% filter(district == 6), 
                            aes(x = factor(school_year), y = share_schools_ldp)) +
  geom_bar(stat = "identity",color="black", fill="gray") +
  geom_text(aes(label=
                  paste0(I(round(share_schools_ldp, digits = 2)), "%")), 
            position=position_dodge(width=0.9), vjust=-0.45, size = 2.5) +
  scale_x_discrete(labels= c("2011-2012", "2012-2013", "2013-2014", "2014-2015",
                             "2015-2016", "2016-2017", "2017-2018", "2018-2019",
                             "2019-2020")) +
  labs(x = "School Year", y = "Share of Schools Receiving \n 1+ ldp Projects") +
  scale_y_continuous(limits = c(0,20), labels = function(x) paste0(x, "%"))+
  theme_bw() +
  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "black"),
        axis.text.x = element_text(angle = 45, hjust=1))

## Panel G
share_schools_ldp7 = ggplot(schools_received %>% filter(district == 7), 
                            aes(x = factor(school_year), y = share_schools_ldp)) +
  geom_bar(stat = "identity",color="black", fill="gray") +
  geom_text(aes(label=
                  paste0(I(round(share_schools_ldp, digits = 2)), "%")), 
            position=position_dodge(width=0.9), vjust=-0.45, size = 2.5) +
  scale_x_discrete(labels= c("2011-2012", "2012-2013", "2013-2014", "2014-2015",
                             "2015-2016", "2016-2017", "2017-2018", "2018-2019",
                             "2019-2020")) +
  labs(x = "School Year", y = "Share of Schools Receiving \n 1+ ldp Projects") +
  scale_y_continuous(limits = c(0,25), labels = function(x) paste0(x, "%"))+
  theme_bw() +
  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "black"),
        axis.text.x = element_text(angle = 45, hjust=1))